package xyz.syyrjx.blog.interceptor;


import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class LoginInterceptor implements HandlerInterceptor {
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        boolean flag = false;
        if(null != request.getSession().getAttribute("user")){
            flag = true;
        }else{
            request.getRequestDispatcher("/login").forward(request,response);
        }
        return flag;
    }
}
